<?php

abstract class BaseWidget {
	public $options = array();
	public $attributes = array();
	
	public function __construct($options = array(), $attributes = array()) {
		$this->options = $options;
		$this->attributes = $attributes;
	}
	
	public function render($name, $value = null, $attributes = array()) {
		$attributes = array_merge($this->attributes, $attributes);
		return $this->doRender($name, $value, $attributes);
	}
	
	abstract public function doRender($name, $value = null, $attributes = array()); // Implemented by subclasses
	
	public function renderTag($tag, $attributes, $innerHTML = false) {
		$html = '<'.$tag;
		foreach ($attributes as $name=>$value) {
			$html .= ' '.$name.'="'.$value.'"';
		}
		if ($innerHTML === false) {
			return $html.' />';
		} else {
			return $html.'>'.$innerHTML.'</'.$tag.'>';
		}
	}

}
